const BinaryTree = require("../utils/binaryTree")
let arr = [3,9,20,null,null,15,7]
let rootObj = new BinaryTree(arr);
var levelOrder = function(root) {
    if(!root)return []
    let result = []
    let queue =[root]
    while(queue.length){
        const levelSize = queue.length
        const currentLevel = []
        for (let i = 0; i < levelSize; i++) {
            const node  = queue.shift()
            currentLevel.push(node.val)
            if(node.left){
                queue.push(node.left)
            }
            if(node.right){
                queue.push(node.right)
            }
        }
        result.push(currentLevel)
    }
    return result
};


const result = levelOrder(rootObj.root)
console.log("🚀 ~ result:", result)
